﻿<script type="text/javascript">
    $(document).ready(function () {
        var p = new singlepage();
        p.c = "Way.Bus.Wms.Controllers.BaseData.DepotwbsController";
        p.applyTo = "t1";
        p.isgridcheck = true;
        p.init();
        p.onCommandClick = function (command, form, item) {
            var source = this.datasource;
            if (command == "remove") {
                var rows = source.grid.getcheckrows();
                var id = "";
                for (var i in rows) {
                    if (id === "")
                        id = rows[i].ID;
                    else
                        id += "," + rows[i].ID;
                }
                var e = source.post(command, "reductionid=" + id);
                if (e && e.error) {
                    $.messager.alert('异常', e.errormsg, 'error');
                }
                else {
                    source.reload();
                    $.messager.show({ title: '消息', msg: '删除完成。', showType: 'show' });
                }
                return false;
            }
        }

        var f = new childform();
        f.parent = p.datasource;
        f.init();
        var box1 = f.findbox("KID");
        box1.applyTo = "k1";
        box1.width = 140;
        box1.init();
        box1.onevent();
        p.kid = box1;
        p.ktree = initkh();
        p.wtree = initck();
    });
    function initkh() {
        var source = new datasource();
        source.c = "Way.Bus.Controllers.CommodityClassController";
        source.init();
        var t = new tree();
        t.isload = true;
        t.checkbox = true;
        t.cascadeCheck = true;
        t.applyTo = "k2";
        t.datasource = source;
        t.init();
        return t;
    }
    function initck() {
        var source = new datasource();
        source.c = "Way.Bus.WMS.Controllers.WareHouseController";
        source.init();
        var t = new tree();
        t.isload = true;
        t.checkbox = true;
        t.cascadeCheck = true;
        t.applyTo = "w1";
        t.datasource = source;
        t.init();
        return t;
    }
    function saveconfig(data) {
        var p = data.page;
        var kid = p.kid.val();
        if (kid == "" || kid == 0) {
            $.messager.alert('异常', "客户未选择，必须选择客户！", 'error');
            return;
        }
        var lids = p.ktree.getchecked();
        if (lids == null || lids.length == 0) {
            $.messager.alert('异常', "商品类别未选择，必须选择商品类别！", 'error');
            return;
        }
        var wt = p.wtree;
        var dids = wt.getchecked();
        if (dids == null || dids.length == 0) {
            $.messager.alert('异常', "货位未选择，必须选择货位！", 'error');
            return;
        }
        var dm = [];
        for (var i in dids) {
            var wid=getwid(dids[i], wt);
            for (var l in lids) {
                var obj = {};
                obj.KID = kid;
                obj.DID = dids[i].id;
                obj.WID = wid;
                obj.LID = lids[l].id;
                dm.push(obj);
            }
        }
        var d = "dm=" + webjs.jsonval(dm);
        data.source.submit(data.command, d, function (e) {
            data.comm.isclicking = false;
            if (e && e.error) {
                $.messager.alert('异常', e.errormsg, 'error');
            }
            else {
                data.source.reload();
                $.messager.show({ title: '消息', msg: data.title + '完成。', showType: 'show' });
            }
        });
        function getwid(node,wt) {
            var t = wt.getparent(node);
            if (t == null)
                return node.id;
            else {
                return getwid(t, wt);
            }
        }
    }
    function import1(data) {
        try {
            $('<div id="d2"><div id="d3"/></div>').appendTo($("#temp"));
            var p1 = new datasource();
            p1.c = "Way.Bus.Controllers.ExcelDRController";
            p1.applyTo = "d3";
            window.ddata = data;
            window.pdata = p1;
            p1.init();

            $('#d2').dialog({
                title: "导入数据",
                collapsible: false,
                resizable: false,
                width: 700,
                height: 400,
                cache: false,
                href: "Views/manager/Exceldr.htm",
                onClose: function () {
                    $(this).panel('destroy');
                    $("#temp").empty();
                    window.ddata = null;
                }
            });
        } catch (e) {

        }
    }
</script>
<div class="easyui-layout" fit="true">
<div region="west" split="true" style="height:auto;width:200px" title="客户商品选择"><div id="k1"/><div id="k2"/></div>
<div region="east" split="true" style="height:auto;width:200px" title="仓库货位选择"><div id="w1"/></div>
<div region="center" style="height:auto;width:auto;">
<div id="t1"></div>
</div>
</div>
